package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.BlackList;
import com.tanhua.domain.db.Question;
import com.tanhua.domain.db.Settings;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.dubbo.mapper.SettingsMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 通用设置服务接口实现类
 */
@Service
public class SettingsApiImpl implements SettingsApi {
    @Autowired
    private SettingsMapper settingsMapper;

    @Override
    public Settings findByUserId(Long userId) {
        QueryWrapper<Settings> queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id", userId);
        return settingsMapper.selectOne(queryWrapper);
    }


    /**
     * 通知设置-修改是否通知
     */
    @Override
    public void updateNotification(boolean likeNotification, boolean pinglunNotification, boolean gonggaoNotification, Long userId) {
        Settings settings = new Settings();//修改的数据
        settings.setLikeNotification(likeNotification);
        settings.setPinglunNotification(pinglunNotification);
        settings.setGonggaoNotification(gonggaoNotification);
        QueryWrapper<Settings> queryWrapper = new QueryWrapper<>();//条件
        queryWrapper.eq("user_id", userId);
        settingsMapper.update(settings, queryWrapper);
    }

    /**
     * 通知设置-保存
     *
     * @param likeNotification
     * @param pinglunNotification
     * @param gonggaoNotification
     * @param userId
     */
    @Override
    public void save(boolean likeNotification, boolean pinglunNotification, boolean gonggaoNotification, Long userId) {
        Settings settings = new Settings();//修改的数据
        settings.setLikeNotification(likeNotification);
        settings.setPinglunNotification(pinglunNotification);
        settings.setGonggaoNotification(gonggaoNotification);
        settings.setUserId(userId);
        settingsMapper.insert(settings);
    }



}
